package co.fitstart.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.user.distributor.Distributor;

/**
 * 
 * @author mohanlan
 *
 */
@Dynamic("hibernate")
public interface DistributorDao {
    
    @Limit
    @Query("FROM Distributor WHERE disabled = false")
    public List<Distributor> listDistributor(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @return
     */
    @Query("FROM Distributor WHERE disabled = false AND purchaserTotal != 0")
    public List<Distributor> listDistributor();
    
    /**
     * 
     * @param userId
     * @return
     */
    @Query("FROM Distributor WHERE disabled = false AND user.id = :userId")
    public Distributor loadDistributor(@Variable("userId") Long userId);
    
    /**
     * 
     * @param distributor
     */
    @Execute("UPDATE DistributorUserRelation SET disabled = true WHERE distributor = :distributor")
    public void deleteRelation(@Variable("distributor") Distributor distributor);
}
